import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.util.JSONPObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 示例：
 * {
 * "a":"1",
 * "b": {
 *  "c":"2",
 *      "d": {
 *          "e": "3"
 *      }
 *  }
 * }
 * <p>
 * 转化为：
 * a = 1
 * b.c=2
 * b.d.e=3
 */
public class MapTest {


    public static void main(String[] args) {

    }

    public static Map<String, Integer> convertStrToMap(String str) {
        Map<String, Integer> mapResult = new HashMap<String, Integer>();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map<String, Object> map = objectMapper.readValue(str, Map.class);
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                Object value = entry.getValue();
                if (value instanceof String) {
                    mapResult.put(entry.getKey(), Integer.valueOf(value.toString()));
                    continue;
                }
                StringBuilder strBu = new StringBuilder();
                strBu.append(entry.getKey());
                Map<String, Object> subValue = (Map<String, Object>) value;
                for (Map.Entry<String, Object> entrySu : subValue.entrySet()) {
                    Object valueSu = entrySu.getValue();
                    if (valueSu instanceof String) {
                        strBu.append(".").append(entrySu.getKey());
                        mapResult.put(strBu.toString(), Integer.valueOf(value.toString()));
                        continue;
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
